package com.itjason.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itjason.mapper.WxNationDialectMapper;
import com.itjason.po.NationDataPO;
import com.itjason.service.WxNationalDialectPageService;
import com.itjason.vo.NationDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Author:JasonLong
 * Date:2023/5/12
 * Time:0:31
 * 民族方言语言包业务接口实现类
 */
@Service
public class WxNationDialectPageServiceImpl implements WxNationalDialectPageService {

    @Autowired
    private WxNationDialectMapper nationDialectMapper;

    /**
     * @param nationFlag
     * @return List
     * 该方法业务逻辑设计为：使用民族标记这个参数去数据库获取为被删除的对应民族的数据
     */
    public List<NationDataVO> getNationLanguagePack(String nationFlag) {
        QueryWrapper<NationDataPO> wrapper = new QueryWrapper<>();
        String[] split = nationFlag.split("语", 0);
        System.out.println("split = " + Arrays.toString(split));
        //修改为模糊查询
        wrapper.like("nation_flag", split[0]).eq("deleted", 0);
        List<NationDataVO> nationDataVOList = nationDialectMapper.selectList(wrapper).stream().map(m -> {
            NationDataVO nationDataVO = new NationDataVO();
            nationDataVO.setNationVoiceurl(m.getNationVoiceurl());
            nationDataVO.setNationTranslation(m.getNationTranslation());
            nationDataVO.setIsplay(m.getIsplay());
            nationDataVO.setNationFlag(m.getNationFlag());
            return nationDataVO;
        }).collect(Collectors.toList());
        return nationDataVOList;
    }

    @Override
    public List getNationDataByKeyword(String keyword, String nationFlag) {
        QueryWrapper<NationDataPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nation_translation", keyword).like("nation_flag", nationFlag).eq("deleted", 0);
        List<NationDataVO> nationDataVOList = nationDialectMapper.selectList(queryWrapper).stream().map(m -> {
            NationDataVO nationDataVO = new NationDataVO();
            nationDataVO.setNationVoiceurl(m.getNationVoiceurl());
            nationDataVO.setNationTranslation(m.getNationTranslation());
            nationDataVO.setIsplay(m.getIsplay());
            nationDataVO.setNationFlag(m.getNationFlag());
            return nationDataVO;
        }).collect(Collectors.toList());
        return nationDataVOList;
    }


}
